﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model;

namespace DokterAfspraken.AdminPages
{
    public partial class LoginScreenAdminDoctor : System.Web.UI.Page
    {
        protected void Page_PreInit(object sender, EventArgs e)
        {
            LoginFactory myLoginFactory = new LoginFactory();
            if (myLoginFactory.CheckLogin() == true)
            {
                Model.DataModelManager manager = new DataModelManager();
                HttpCookie myCookie = new HttpCookie("UserSettings");
                myCookie = Request.Cookies["UserSettings"];
                if (manager.getAccountType(myCookie["dokterspraktijk_username"].ToString()) == "Administrator")
                {
                    Response.Redirect("../AdminPages/Adminkeuzescherm.aspx");
                }
                else if (manager.getAccountType(myCookie["dokterspraktijk_username"].ToString()) == "Arts")
                {
                    Response.Redirect("../DoctorPages/Dokterkeuzescherm.aspx");
                }
                else if (manager.getAccountType(myCookie["dokterspraktijk_username"].ToString()) == "Patient")
                {
                    Response.Redirect("../PatientPages/PatientAgenda.aspx");
                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            LoginFactory myLoginFactory = new LoginFactory();
            if (myLoginFactory.CheckLogin() == true)
            {
                Model.DataModelManager manager = new DataModelManager();
                HttpCookie myCookie = new HttpCookie("UserSettings");
                myCookie = Request.Cookies["UserSettings"];
                if (manager.getAccountType(myCookie["dokterspraktijk_username"].ToString()) == "Administrator")
                {
                    Response.Redirect("../AdminPages/Adminkeuzescherm.aspx");
                }
                else if (manager.getAccountType(myCookie["dokterspraktijk_username"].ToString()) == "Arts")
                {
                    Response.Redirect("../DoctorPages/Dokterkeuzescherm.aspx");
                }
                else if (manager.getAccountType(myCookie["dokterspraktijk_username"].ToString()) == "Patient")
                {
                    Response.Redirect("../PatientPages/PatientAgenda.aspx");
                }
            }
        }

        protected void btnAanmelden_Click(object sender, EventArgs e)
        {
            LoginFactory mijnloginfactory = new LoginFactory();
            try
            {
                mijnloginfactory.Inloggen(txtGebruikersnaam.Text, txtPaswoord.Text, true);
                Page_PreInit(sender, e);
            }
            catch
            {
                txtGebruikersnaam.Text = "";
                txtPaswoord.Text = "";
                lblFoutmelding.Visible = true;
            }
            
        }
    }
}